﻿using EasyClassWEBAPI.EntityClass;
using EasyClassWEBAPI.Utils;
using RestSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            
            string FilePath = @"E:\社交网络大数据分析\8.17 周报.md";
            FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
            Byte[] body = new Byte[(int)fs.Length];
            fs.Read(body, 0, body.Length);
            fs.Close();
            Post post = new Post { Title = "EF core使用指南", Category = "程序设计", StudyGroupID = 1,CreateTime=DateTime.Now,ContentName= "2020-11-09--10-49-33.md" };
            string PostStr = TypeToString.PostToString(post);
            Console.WriteLine(PostStr);
            Console.WriteLine(DateTime.Now.ToString("yyyy-M-dd--HH-mm-ss")+".md");
            Console.ReadLine();
            
            //Console.WriteLine(SimilarityComputation.DamerauLevenshteinMethod("设计", "设计"));
            //DownloadFile();

        }
        public static async void DownloadFile()
        {
            string url = "https://localhost:5001/resource/download?filename=基于行为轨迹信息的社交网络社区发现框架.docx&isGroup=true&ID=2";
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage response = await httpClient.GetAsync(url);
            Stream receiveStream = await response.Content.ReadAsStreamAsync();
            //StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
            StreamToFile(receiveStream, @"E:\基于行为轨迹信息的社交网络社区发现框架.docx");
        }
        public static void StreamToFile(Stream stream, string fileName)

        {
            // 把 Stream 转换成 byte[]
            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);
            // 设置当前流的位置为流的开始
            stream.Seek(0, SeekOrigin.Begin);
            // 把 byte[] 写入文件
            FileStream fs = new FileStream(fileName, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);
            bw.Write(bytes);
            bw.Close();
            fs.Close();
        }
    }
}
